import requests


class Actor:
    def __init__(self):
        self.session = requests.Session()
        headers = {
            # 若登录失效或再次登录,需要重新赋值
            "authorization" : "Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImRkOTRhYmE4LWU1YzItNGU0OC04ODBiLWU1MGRhMzM3NDQ5MyJ9.mNxtA5bJ5dy620JAY_fHwUEbUtDwxbhhbBadDkHI7CYYrkqJPvl894pjz3fTVFIAnZ86FbxFzASM9cJB_eGYQQ"
        }
        self.session.headers.update(headers)

    # 根据ID查询 演员信息 返回值  接口返回什么 此函数的返回值 取它的JSON数据
    def search_actor_id(self, id):
        # pass
        # return  resp.json()
        url = f"http://1.13.8.34:10010/system/actor/{id}"
        resp = self.session.get(url=url)
        return resp

    # 根据演员的姓名查询演员信息
    def search_actor_name(self, actorName):
        # pass
        url = f"http://1.13.8.34:10010/system/actor/list"
        params = {
            'pageNum': 1,
            'pageSize': 10,
            'actorName': actorName
        }
        resp = self.session.get(url=url, params=params)
        return resp

    # 上传文件
    def upload_image(self, path):
        # pass
        url = "http://1.13.8.34:10010/common/upload"
        fp = open(path, mode='rb')
        files = {'file': fp}
        resp = self.session.post(url=url, files=files)
        return resp

    # 保存演员
    def add_actor(self, actorName, description):
        # pass
        url = 'http://1.13.8.34:10010/system/actor'
        body = {"actorId": None, "actorName": actorName, "actorImg": "8ef2471d-4c47-4274-812a-99491b4db1a8.png",
                "actorDesc": description, "followers": None, "boxOffice": None}
        resp = self.session.post(url=url, json=body)
        return resp

    # 更新演员信息
    def modify_actor(self, actorId, actorName, description):
        # pass
        url = 'http://1.13.8.34:10010/system/actor'
        body = {"searchValue": None, "createBy": None, "createTime": None, "updateBy": None, "updateTime": None,
                "remark": None, "params": {}, "actorId": actorId, "actorName": actorName,
                "actorImg": "8ef2471d-4c47-4274-812a-99491b4db1a8.png", "actorDesc": description, "followers": 0,
                "boxOffice": 0}
        resp = self.session.put(url = url,json=body)
        return resp

    # 删除演员信息
    def remove_actor(self, actorId):
        # pass
        url = f'http://1.13.8.34:10010/system/actor/{actorId}'
        resp = self.session.delete(url=url)
        return resp
if __name__ == '__main__':
    actor = Actor()
    # print(actor.search_actor_id("3339").json())
    # print(actor.search_actor_name('灭绝').json())
    # print(actor.upload_image("./imags/c.png").json())
    # print(actor.add_actor('陈泽','著名主播').json())
    # print(actor.modify_actor(3342,'陈泽牛逼!!!','陈泽VS宇将军!!!').json())
    print(actor.remove_actor(3341).json())